﻿using B.S.Database.Interface.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B.S.Database.Interface.Impment
{
    public class BaseResotity<T> : IBaseResotity<T> where T : class
    {
        private readonly DataDbcontext db;

        public BaseResotity(DataDbcontext db)
        {
            this.db = db;
        }
        public DataDbcontext Db
        {
            get { return db; }
        }

        public int Add(T entity)
        {
            db.Add(entity);
            return db.SaveChanges();
        }

        public T Get(int id)
        {
            return db.Set<T>().Find(id);
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>().AsQueryable();
        }

        public int Update(T entity)
        {
            db.Update(entity);
            return db.SaveChanges();
        }

        public int Delete(T entity)
        {
            db.Remove(entity);
            return db.SaveChanges();
        }
    }
}
